/*
 * 描述:初始化AO的license
 * 作者:wx
 * 时间:20161108
 */
package com.ao.utils;

import java.io.IOException;
import java.net.UnknownHostException;

import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;

public class InitAOLicense {
	
	public static void  init() throws UnknownHostException, IOException{
		EngineInitializer.initializeEngine();
		AoInitialize aoInit = new AoInitialize();
	    initializeArcGISLicenses(aoInit);
	}
	
	private static void initializeArcGISLicenses(AoInitialize aoInit) {
	    try {
	      if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) 
	          == esriLicenseStatus.esriLicenseAvailable)
	        aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
	      else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeBasic) 
	          == esriLicenseStatus.esriLicenseAvailable)
	        aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
	      else{
	        System.err.println("Could not initialize an Engine or Basic License. Exiting application.");
	        System.exit(-1);
	      }
	    } catch (Exception e) {e.printStackTrace();}
	  }
}
